// -*- coding: utf-8 -*-

/**
 * @file hybrid_newton_reduction.h
 * @brief Implementation of a consistency for hybrid problems.
 */

#ifndef _HYBRID_NEWTON_REDUCTION1_H
#define _HYBRID_NEWTON_REDUCTION1_H

#include "vnode.h"

#include "hybrid_config.h"
#include "hybrid_var.h"
#include "hybrid_model.h"
#include "hybrid_newton_reduction.h"

NAMESPACE_ELISA

/**
 * @ingroup Hybrid
 * @class HybridNewtonReduction1
 * @brief Projection operator implementing interval Newton method for hybrid problems
 * @duprecated
 */
class HybridNewtonReduction1 : public Reduction
{
public:
	/**
 	 * Constructor
 	 * @param c the constraint to reduce
 	 * @param v the var that the domain must be reduced
 	 * @param cons the factory for IntrevalForm
	 */
	HybridNewtonReduction1(ContConstraint *cc, IntervalFormFactory *cons)
	    : m_constr(*cc),
		  m_odeSolver(cc->rep()->getAD().get()),
		  m_initT(), m_endT()
	{
		Reduction::post(cc);

		//m_odeSolver.setTols(1e-10, 1e-10);
		m_odeSolver.setTols(1e-20, 1e-20);
		m_odeSolver.setOrder(20);
		//m_odeSolver.setOrder(50);
		m_odeSolver.setHmin(1e-13);
		//m_odeSolver.setOneStep(vnodelp::on);
	}

	/**
 	 * Destructor
 	 */
	~HybridNewtonReduction1()
	{
	}

	/// Base class's virtual methods
	//@{
	double priority() const
	{
		return 10.0;
	}

	bool narrow(const bool, VNIntVec&, VNInterval&, const double&, VNIntVec&);
	bool newtonIt(VNIntVec&, VNInterval&, const double&, VNIntVec&);

	bool reductionAlgorithm();
	//@}


	string getReductionName() const
	{
		return "HybridNewton";
	}

	void print(std::ostream & os, std::string indent, VecConstraints *v) const
	{
		os << "HybridNewtonReduction [";
		printConstraints(os, "", v);
		os << "]";
	}

	static bool dump;

private:
	static const double MinH;
	static const int    Ratio;
	static const double Factor;

#ifdef HYBRID_PROFILE
	// ダンプ出力。
	//static ofstream odeOut;
#endif

	// continuous constraint
	ContConstraint& m_constr;

	VNInterval	m_initT;
	VNInterval	m_endT;
	
	vnodelp::VNODE			m_odeSolver;

	/// Copy protection
	HybridNewtonReduction1& operator=(const HybridNewtonReduction&);
	HybridNewtonReduction1(const HybridNewtonReduction&);
};

END_NAMESPACE_ELISA

#endif //HYBRID_NEWTON_REDUCTION1_H
